package com.bwie.config;

import com.bwie.task.StockWaringJob;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class QuartzConfig {
    @Bean
    public JobDetail stockJobDetail() {
        return JobBuilder.newJob(StockWaringJob.class)
                .withIdentity("定时检查库存")
                .storeDurably()
                .build();
    }

    @Bean
    public Trigger myJobTrigger() {
        return TriggerBuilder.newTrigger()
                .forJob(stockJobDetail())
                .withIdentity("触发定时检查任务")
                .withSchedule(CronScheduleBuilder.cronSchedule("0/5 * * * * ?")) // 每5秒执行一次
                .build();
    }
}
